import java.sql.*;

public class ConnectionManager
{
	public static Connection getConnection(String username, String password)
	{
		Connection connection = null;
	
		try
		{
			DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
			String url = "jdbc:oracle:thin:@db10.cs.pitt.edu:1521:dbclass";
			connection = DriverManager.getConnection(url, username, password);
			connection.setAutoCommit(false);
		}
		catch(Exception Ex)
		{
			System.out.println("Error connecting to database.  Machine Error: "+Ex.toString());
			Ex.printStackTrace();
		}
		finally
		{
			return connection;
		}
	}
	
	public static Statement createStatement(Connection c)
	{
		Statement statement = null;
	
		try
		{	
			statement = c.createStatement();
		}
		catch(Exception Ex)
		{
			System.out.println("Error running the sample queries.  Machine Error: "+Ex.toString());
		}
		finally
		{
			return statement;
		}
	}
	
	public static void closeConnection(Connection c)
	{
		try
		{		
			c.close();
		}
		catch(Exception Ex)
		{
			System.out.println("Error running the sample queries.  Machine Error: "+Ex.toString());
		}					
	}
}
